<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="<%=basePath %>front/css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<link href="<%=basePath %>front/css/component.css" rel="stylesheet" type="text/css" media="all" />
<link href="<%=basePath %>front/css/style_grid.css" rel="stylesheet" type="text/css" media="all" />
<link href="<%=basePath %>front/css/style.css" rel="stylesheet" type="text/css" media="all" />
<!-- font-awesome-icons -->
<link href="<%=basePath %>front/css/font-awesome.css" rel="stylesheet"> 
<!-- //font-awesome-icons -->
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800" rel="stylesheet">
</head>
<body>
<!-- banner -->
<div class="wthree_agile_admin_info">
<jsp:include page="top.jsp"></jsp:include>
		  <!-- /w3_agileits_top_nav-->
		  <!-- /nav-->
		  
								
							<!-- //buttons_w3ls_agile -->
											












				<div class="inner_content_w3_agile_info two_in" style="margin-top:90px;">
					  <h2 class="w3_inner_tittle">我的余额<i class="fa fa-cny"></i><font id="money">222</font><a href="<%=basePath %>front/jsp/myGoods.jsp" style="float:right;margin-right:20px;"><i class="fa fa-truck"></i></a></h2>

				<div id="goodsList">??????</div>
					  		       
								
								









</body>
</html>
<script>
$(document).ready(function(){
	showAll();
	getmoney();
});
	function showAll(){
		debugger;
		
		var l = document.getElementById("goodsList");
		var everything =document.getElementById("everything").value;
		l.innerHTML='';
		$.ajax( {
						url:'<%=basePath%>goods/findAll',
						async: false,
						type:'post',
						data: {
							
						},
						datatype : "json",//"xml", "html", "script", "json", "jsonp", "text".           
						success : function(data) {
							var json=eval('(' + data + ')');
							$.each(json, function (n, item) {
								if(item.name.indexOf(everything)>=0){
									addGoods(n,item);
								}
								
							});
						},
						error : function() {
			                alert("异常！！！");
			                
			            }
				});
	}
	function addGoods(n,item){
		var val = "<div class=\"buttons_w3ls_agile\">"+
		"<div class=\"col-md-6 button_set_one three agile_info_shadow\">"+
		 "<h3 class=\"w3_inner_tittle two\">"+item.name+"</h3>"+
				"<div id=\"holder\">"+
					"<img src=\"../../"+item.picpath+"\" style=\"width: 300px;height: 250px; margin-left: -250px;\" >"+
					"<p>￥"+item.price+"</p>"+
					"<div class=\"button\" onclick=\"addMybought('"+item.id+"','"+item.price+"')\" style=\"margin-left: 200px;\">"+
						"<p class=\"btnText\">买?</p>"+
						"<div class=\"btnTwo\">"+
						  "<p class=\"btnText2\">GO!</p>"+
						"</div>"+
					 "</div>"+
					"</div>"+		
		"</div>"+	
	"</div>";

		$("#goodsList").append(val);
	}
	
	
	function getmoney(){
		debugger;
		
		var l = document.getElementById("money");
		l.innerHTML='';
		$.ajax( {
			url:'<%=basePath%>puser/subtract4',
			async: false,
			type:'post',
			data: {
				
			},
			datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
			success : function(data) {
				$("#money").append(data);
				
			},
			error : function() {
	            alert("异常！！！");
	            
	        }
	});
	}
	
	function addMybought(id,price){
		debugger;
		var ll = parseInt(document.getElementById("money").innerHTML);
		var pp=parseInt(price);
		if(ll<pp){
			alert("余额不足！！");
			throw SyntaxError();
		}
		$.ajax( {
			url:'<%=basePath %>bought/addMybought',
			async: false,
			type:'post',
			data: {
				id:id 
			},
			datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
			success : function(data) {
				getmoney();
				alert("购买成功！！");
				
			},
			error : function() {
	            alert("添加我的奖品异常！！！");
	            
	        }
	});
	}
	
	
</script>